<?php 
include("config.php");
session_start();
require('db/opendb.php');
$listing_id = $_GET['listing_id'];

$mquery = "select p.*, po.Owner from PROPERTIES p LEFT JOIN Prop_Owner_Con po on (p.OID=po.Prop_OID) WHERE p.OID = '".$listing_id."'";
$mresult = mysql_query($mquery) or die ("SQL Error".mysql_error());
if(mysql_num_rows($mresult)>0) {
	$row = mysql_fetch_assoc($mresult);
//	echo "<pre>";print_r($row);exit;
	$sql = "SELECT * FROM Users WHERE ID='{$row['Owner']}'";
	$agent_rs = mysql_query($sql) or die ("SQL Error".mysql_error());
	$agent = mysql_fetch_assoc($agent_rs);
	//		echo "<pre>";print_r($agent);exit;
}
else {
	echo "Listing not found";exit;
}

if($row['bg_type']=='c') {
	$style = "background-color:{$row['bg_color']}";
}
else {
	$sql = "SELECT * FROM Listing_Images WHERE is_bg = '1' AND Listing_ID = '$listing_id'";
	$result = mysql_query($sql) or die ("SQL Error".mysql_error());
	if(mysql_num_rows($result)>0) {
		$bg_img_row = mysql_fetch_assoc($result);
		$bg_image = $bg_img_row['Path'];
	}
	else {
		$sql = "SELECT * FROM Listing_Images WHERE Main_Photo = '1' AND Listing_ID = '$listing_id'";
		$result = mysql_query($sql) or die ("SQL Error".mysql_error());
		if(mysql_num_rows($result)>0) {
			$bg_img_row = mysql_fetch_assoc($result);
			$bg_image = $bg_img_row['Path'];
		}
		else {
			$sql = "SELECT * FROM Listing_Images WHERE Listing_ID = '$listing_id' LIMIT 1";
			$result = mysql_query($sql) or die ("SQL Error".mysql_error());
			if(mysql_num_rows($result)>0) {
				$bg_img_row = mysql_fetch_assoc($result);
				$bg_image = $bg_img_row['Path'];
			}
			else {
				$bg_image = '';
			}
		}
	}
	if(!$bg_image)
	$style = "background-color:#000000";
	else 
	$style = "background:url('".SITE_ROOT_URL."listing_images/".$bg_image."')";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">

	<head profile="http://gmpg.org/xfn/11">

	<title>Realivent:<?php echo $row['TITLE']?></title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

</head>

<body style="<?php echo $style?>" onload="document.getElementById('loading').style.display='none'">
<style>
#center_content{margin-top:10px;background-color: #FFFFFF;width:875px;}
#list_menu {    background-color: #000000;
    float: left;
    list-style: none outside none;
    width: 100%;margin:0px;padding:0px;}
#list_menu li {    background-color: #000000;
    float: left;
    list-style: none outside none;
    margin: 0;
    padding: 5px 26px 5px 10px;
    text-align: left;}
#list_menu li a{ color: #FFFFFF;
    font-family: "Helvetica Neue","Helvetica",Arial,sans-serif;
    font-size: 19px;text-decoration:none;}
.header{width:875px;text-decoration: none;}
img {border:0px;}
.infobox img {margin:1px}
</style>
<!--Loading display while images load-->
<div id="loading">&nbsp;</div>
		
<!--Content Area-->
<div id="content-wrapper">
	
	<center>
	<div class="header">
	<?php include(ABS_PATH."hover_content.php")?>
	</div>
	<div id="center_content">
	<ul id="list_menu">
		<li><a href="<?php echo SITE_ROOT_URL?>vt/<?php echo $listing_id?>">Home Tour</a></li>
		<li><a href="<?php echo SITE_ROOT_URL?>popup.php?page=detail&listing_id=<?php echo $listing_id?>">Property Detail</a></li>
		<li><a href="<?php echo SITE_ROOT_URL?>popup.php?page=neighbour&listing_id=<?php echo $listing_id?>">Neighborhood Info</a></li>
		<li><a href="<?php echo SITE_ROOT_URL?>popup.php?page=my_list&listing_id=<?php echo $listing_id?>">My Listings</a></li>
		<li><a href="<?php echo SITE_ROOT_URL?>popup.php?page=contact&listing_id=<?php echo $listing_id?>">Contact</a></li>
	</ul>
	<div style="clear:both"></div>
	<?php 
	switch ($_GET['page']) {
		case 'detail':
		include(ABS_PATH.'inc.property_details.php');
		break;
		case 'neighbour':
		include(ABS_PATH.'inc.neighborhood.php');
		break;
		case 'my_list':
		include(ABS_PATH.'inc.featured_listings.php');
		break;
		case 'contact':
		include(ABS_PATH.'inc.contact.php');
		break;
	}
	?>
	</div>
	</center>
</div>


</body>
</html>
